import { createRouter, createWebHashHistory } from "vue-router";
import HomeView from "@/views/HomePage.vue";
import CodeRain from "@/views/CodeRain.vue";
import LoginView from "@/views/LoginView.vue";
import ApproveManuscriptsView from "@/views/ApproveManuscripts.vue";
import UpdateMessage from "@/views/UpdateMessage.vue";
import TestPage from "@/views/TestView.vue";
// main.js
const routes = [
  {
    path: "/",
    name: "home",
    component: HomeView,
    meta: {
      layout: "MainLayout",
      title: "芸窗-您的期刊采编平台",
    },
  },
  {
    path: "/approveManuscripts",
    name: "approveManuscripts",
    component: ApproveManuscriptsView,
    meta: {
      layout: "MainLayout",
      title: "芸窗-审批稿件页面",
    },
  },
  {
    path: "/updateMessage",
    name: "updateMessage",
    component: UpdateMessage,
    meta: {
      layout: "MainLayout",
      title: "芸窗-修改信息页面",
    },
  },
  {
    path: "/testPage",
    name: "testPage",
    component: TestPage,
    meta: {
      layout: "MainLayout",
      title: "芸窗-测试页面",
    },
  },

  {
    path: "/codeRain",
    name: "codeRain",
    component: CodeRain,
    meta: {
      title: "芸窗-测试页面",
    },
  },
  {
    path: "/login",
    name: "login",
    component: LoginView,
    meta: {
      title: "加入芸窗",
    },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

// 全局前置守卫
router.beforeEach((to, from, next) => {
  // 清除bootstrap点击侧边栏后的Offcanvas相关样式
  document.body.style.overflow = "";
  document.body.style.paddingRight = "";
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  if (to.meta.favicon) {
    document.head.innerHTML = `<link rel="icon" href="${to.meta.favicon}">`;
  }
  next();
});

export default router;
